package com.starbaba.externalpage.view;

import java.io.IOException;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.base.common.log.LogService;
import com.opensymphony.xwork2.ActionSupport;
import com.starbaba.collaborate.model.CollaborateResult;
import com.starbaba.core.utils.BeanUtils;
import com.starbaba.core.utils.PropertyParamMapBuilder;
import com.starbaba.core.utils.Struts2Utils;
import com.starbaba.core.utils.json.JsonUtils;
import com.starbaba.core.web.page.PageResponse;
import com.starbaba.core.web.struts2.BaseAction;
import com.starbaba.externalpage.model.ExternalDownBean;
import com.starbaba.externalpage.model.ExternalPageModel;
import com.starbaba.externalpage.model.ExternalResult;
import com.starbaba.externalpage.service.ExternalPageService;
import com.starbaba.externalpage.service.impl.ExternalPageServiceImpl;

/**
 * 直接外部联登推广action
 * @author Administrator
 *
 */
public class ExternalPageAction extends BaseAction {
	
	private ExternalPageService service=new ExternalPageServiceImpl();

	private static final long serialVersionUID = 1L;
	
	private String external_num;
	private String activity_id;
	private String status;
	private String android_url;
	private String ios_url;

	

	public String showPage(){
		paramsMap=PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		service.showpage(paramsMap);
		return ActionSupport.SUCCESS;
	}
	
	public void getExternalPageList(){
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		parsePageRequest();
		PageResponse pageResponse = new PageResponse();
		try {
			List<ExternalPageModel> list = service.getExternalPageList(pageRequest, pageResponse, paramsMap);
			pageResponse.setAaData(list);
			pageResponse.setSEcho(pageRequest.getSEcho());
			sendJsonMessage(JsonUtils.toJson(pageResponse, null, true, null, false));
		} catch (Exception e) {
			LogService.error("查询外部联登外推页列表出错",e);
			e.printStackTrace();
		}
	}
	
	public String toEditorPage(){
		ExternalDownBean bean = service.getUrl(activity_id);
		if(!BeanUtils.checkFieldValueNull(bean)){
			String a_url = bean.getAndroid_url();
			String i_url = bean.getIos_url();
			
			if(!StringUtils.isEmpty(a_url)){
				android_url=a_url;
			}
			
			if(!StringUtils.isEmpty(i_url)){
				ios_url=i_url;
			}
		}
		
		return "editor";
	}
	
	public void saveInfo(){
		ExternalResult result = service.saveExternalInfo(activity_id, external_num, status,android_url,ios_url);
		try {
			sendJsonMessage(JsonUtils.toJson(result, null, true, null, false));
		} catch (IOException e) {
			LogService.error(e);
		}
	}

	public String getExternal_num() {
		return external_num;
	}

	public void setExternal_num(String external_num) {
		this.external_num = external_num;
	}

	public String getActivity_id() {
		return activity_id;
	}

	public void setActivity_id(String activity_id) {
		this.activity_id = activity_id;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getAndroid_url() {
		return android_url;
	}

	public void setAndroid_url(String android_url) {
		this.android_url = android_url;
	}

	public String getIos_url() {
		return ios_url;
	}

	public void setIos_url(String ios_url) {
		this.ios_url = ios_url;
	}
	
}
